<?php

include '../../lib/dbc.php';
require_once ('../../../etc/Connexion.php');
$conn = mysql_connect(SERVER, USER, PASSWORD) or die("erreur de connexion");
mysql_select_db(DATABASE, $conn) or die("erreur de select db");
session_start();

foreach($_GET as $key => $value) {
	$get[$key] = filter($value);
}

$user = mysql_real_escape_string($get['user']);

if(isset($get['cmd']) && $get['cmd'] == 'check') {

if(isset($_SESSION['courrielUtilisateur']) && $user==$_SESSION['courrielUtilisateur']){
    echo '<span style="font-size:14px" class="message">Email actuellement sauvegardé</span>';
    exit();
}
    
    
if(!filter_var($user, FILTER_VALIDATE_EMAIL)){  
    echo '<span style="font-size:14px" class="erreur">Email invalide</span>' ;
    exit();
}

if(empty($user)) {
echo '<span style="font-size:14px" class="erreur">Email incomplet</span>';
exit();
}



$rs_duplicate = mysql_query("select count(*) as total from utilisateur where courrielUtilisateur='$user' ") or die(mysql_error());
list($total) = mysql_fetch_row($rs_duplicate);

	if ($total > 0)
	{
	echo '<span style="font-size:14px" class="erreur">Indisponible</span>';
	} else {
	echo '<span style="font-size:14px" class="message">Disponible</span>';
	}
}

?>